package com.hackordie.commons.hardware.router;

import java.util.ArrayList;
import java.util.List;

import com.hackordie.commons.hardware.components.Firewall;
import com.hackordie.commons.hardware.components.HardDisk;
import com.hackordie.commons.hardware.components.NetworkCard;
import com.hackordie.commons.hardware.computer.Computer;

public class Router extends Computer {
   
    List<String> ipActuallyConnected = new ArrayList<String>();
   
    public Router(String ipRouter, String[] connectedTo) {

        super(1, 0, 100, 1, 1, 0);

        for (int i = 0; i < connectedTo.length; i++) {
            components.add(new NetworkCard("NetworkCard" + (i + 1), 0,
                    ipRouter, 0));
            ((NetworkCard) components.get(i)).setConnectedToIp(connectedTo[i]);
        }

        components.add(new HardDisk("HardDisk1", 0, 1000));
        components.add(new Firewall("Firewall1", 0, 8));

    }

    //getters and setters
    public List<String> getIpActuallyConnected() {
        return ipActuallyConnected;
    }

    public void setIpActuallyConnected(List<String> ipActuallyConnected) {
        this.ipActuallyConnected = ipActuallyConnected;
    }
    
    public void addNewIpConnected(String newIp) {
        ipActuallyConnected.add(newIp);
    }
    
    public void removeNewIpConnected(String ip) {
        
        //buscamos la primera conexion que se corresponda con la ip, y la quitamos
        boolean found = false; 
        int pos = 0;
        
        while(!found && pos < ipActuallyConnected.size()){
            
            if(ipActuallyConnected.get(pos).equals(ip)) {
                ipActuallyConnected.remove(pos);
                found = true;
            }
            pos++;
        }        
    } 
}
